package com.masterclient.app.modules.order.contract;

import android.text.TextUtils;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.masterclient.app.httpservice.RetrofitUtil;
import com.eoner.baselibrary.bean.order.ConfirmPriceBean;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
* Created by TMVPHelper on 2017/12/26
*/
public class DiscountChoosePresenter extends DiscountChooseContract.Presenter{


    @Override
    public void confirmOrderPrice(String address_id, String balance, String bupiao, String productId, String buy_num, String[] product_id, String salesrule_id,String is_original_price,String is_offline) {
        Map<String,String> map = new HashMap<>();
        map.put("address_id",address_id);
        map.put("balance",balance);
        map.put("bupiao",bupiao);
        if(!TextUtils.isEmpty(productId)){
            map.put("buy_product["+productId+"]",buy_num);
        }
        if(!TextUtils.isEmpty(salesrule_id)){
            map.put("salesrule_id",salesrule_id+"");
        }

        if(!TextUtils.isEmpty(is_original_price)){
            map.put("is_original_price",is_original_price);
        }
        if(!TextUtils.isEmpty(is_offline)){
            map.put("is_offline",is_offline);
        }

        Observable<ConfirmPriceBean> observable = RetrofitUtil.getInstance().confirmOrderPrice(map,product_id);
        Disposable disposable = toSubscribe(observable, new Consumer<ConfirmPriceBean>() {
            @Override
            public void accept(@NonNull ConfirmPriceBean bean) throws Exception {
                if("0".equals(bean.getCode())){
                    mView.confirmPriceSuccess(bean.getData());
                }
            }
        },new ThrowableConsumer());
        mRxManager.add(disposable);
    }
}